package com.zjj.juc;

/**
 * @author zhoujunjie
 * @desc TODO
 * @date
 */
import java.util.concurrent.SynchronousQueue;

public class Test2 {
    public static void main(String[] args) {
        SynchronousQueue<Character> queue1 = new SynchronousQueue<>();
        SynchronousQueue<Character> queue2 = new SynchronousQueue<>();

        Thread thread1 = new Thread(() -> {
            try {
                System.out.println("C");
                queue1.put('C');
                queue2.take();
                System.out.println("A");
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        Thread thread2 = new Thread(() -> {
            try {
                queue1.take();
                Thread.sleep(2000);
                System.out.println("B");
                Thread.sleep(2000);
                queue2.put('B');
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        thread1.start();
        thread2.start();

        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}